package com.flowCloud.web.controller.login;


import com.flowCloud.config.log.SystemControllerLog;
import com.flowCloud.config.token.JwtTokenUtil;
import com.flowCloud.result.ResultModel;
import com.flowCloud.result.ResultTools;
import com.flowCloud.web.bean.TblUserBean;
import com.flowCloud.web.controller.login.dto.AuthLoginDto;
import com.flowCloud.web.controller.login.vo.AuthLoginVo;
import com.flowCloud.web.service.login.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


/**
 * @Author: Pompey_hpy
 * @Date: 2020/7/3
 * @Description: 接口Api
 */
@Slf4j
@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private LoginService loginService;

    /**
     * @Description: 授权登录
     * @Author: Pompey_hpy
     * @Date: 2020-10-20
     * @param vo
     * @return: com.jsb.api.result.ResultModel
     */
    //@SystemControllerLog(operation = "授权登录",type = "info")
    @GetMapping(value = "/authLogin")
    public ResultModel authLogin(AuthLoginVo vo){
        log.info("授权登录 [login/authLogin] 接口");
        try {
            AuthLoginDto authLoginDto = loginService.authLogin(vo);
            return ResultTools.success(authLoginDto);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(String.format("【异常错误】授权登录：%s",e.getMessage()));
            return ResultTools.fail(e.getMessage());
        }
    }

    /**
     * @Description: 获取用户信息
     * @Author: Pompey_hpy
     * @Date: 2020-10-20
     * @return: com.jsb.api.result.ResultModel
     */
    @SystemControllerLog(operation = "获取用户信息",type = "info")
    @GetMapping(value = "/getUserInfo")
    public ResultModel getUserInfo(HttpServletRequest request){
        log.info("获取用户信息 [login/getUserInfo] 接口");
        try {
            TblUserBean userInfo = JwtTokenUtil.getUserInfo(request);
            return ResultTools.success(userInfo);
        } catch (Exception e) {
            e.printStackTrace();
            log.error(String.format("【异常错误】获取用户信息：%s",e.getMessage()));
            return ResultTools.fail(e.getMessage());
        }
    }

    /**
     * @Description: 测试
     * @Author: Pompey_hpy
     * @Date: 2020-10-20
     * @return: com.jsb.api.result.ResultModel
     */
    @SystemControllerLog(operation = "测试接口",type = "info")
    @GetMapping(value = "/test")
    public ResultModel test(HttpServletRequest request){
       return ResultTools.success();
    }


}
